//
//  DMWithdrawDepositAccountVC.m
//  DistributionMall
//
//  Created by JHnoplan on 2018/10/17.
//  Copyright © 2018年 JHnoplan. All rights reserved.
//

#import "DMWithdrawDepositAccountVC.h"
#import "DMWithdrawDepositAddVC.h"
#import "DMWithdrawDepositAccountCell.h"
#import "FDSlideBar.h"

@interface DMWithdrawDepositAccountVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (weak, nonatomic) IBOutlet UIView *headView;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) FDSlideBar *sliderBar;


@end

@implementation DMWithdrawDepositAccountVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self startInit];
}

-(void)startInit {
    self.navigationItem.title = @"账号列表";
    self.view.backgroundColor = DMDefaultColor;
    _dataArray = [NSMutableArray new];
    //TODO:-测试数据
    [_dataArray addObjectsFromArray:@[@"",@"",@""]];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.tableFooterView = [self footerView];
    //注册cell
    [self.tableView registerNib:[UINib nibWithNibName:@"DMWithdrawDepositAccountCell" bundle:nil] forCellReuseIdentifier:@"DMWithdrawDepositAccountCell"];
    
    //头部选择View
    [self makeSlideBar];
}

#pragma mark - tableView
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return _dataArray.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 60;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 8;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.01;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    DMWithdrawDepositAccountCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DMWithdrawDepositAccountCell" forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[NSBundle mainBundle]loadNibNamed:@"DMWithdrawDepositAccountCell" owner:self options:nil].firstObject;
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    
}
//左滑删除
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}
// 定义编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}
// 进入编辑模式，按下出现的编辑按钮后,进行删除操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
    }
}
// 修改编辑按钮文字
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    return @"删除";
}

//尾部添加View
-(UIView *)footerView {
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 68)];
    view.backgroundColor = DMWhiteColor;
    view.userInteractionEnabled = YES;
    [view addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addClick)]];
    
    UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 8)];
    line.backgroundColor = DMDefaultColor;
    [view addSubview:line];
    
    UIImageView *iv = [[UIImageView alloc]initWithFrame:CGRectMake((ScreenWidth-20)/2, 17, 20, 20)];
    iv.image = [UIImage imageNamed:@"tianjiazhanghao"];
    [view addSubview:iv];
    
    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(0, 43, ScreenWidth, 17)];
    label.text = @"添加账号";
    label.textColor = DMFontColor;
    label.font = DMFontSize(12);
    label.textAlignment = NSTextAlignmentCenter;
    [view addSubview:label];
    
    return view;
}
-(void)addClick {
    DMWithdrawDepositAddVC *vc = [DMWithdrawDepositAddVC new];
    [self.navigationController pushViewController:vc animated:YES];
}

//头部选择View
-(void)makeSlideBar {
    _sliderBar = [[FDSlideBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, 50)];
    _sliderBar.itemsTitle = @[@"微信", @"支付宝"];
    _sliderBar.backgroundColor = [UIColor clearColor];
    _sliderBar.itemColor = DMFontColor;
    _sliderBar.itemSelectedColor = DMMainColor;
    _sliderBar.sliderColor = DMMainColor;
    [_sliderBar selectSlideBarItemAtIndex:0];
    [_sliderBar slideBarItemSelectedCallback:^(NSUInteger idx) {
        //选择,刷新tableView
        //        _index = idx;
        //
    }];
    [_headView addSubview:_sliderBar];
}

@end
